package com.bit.blog.pojo.response;

import com.bit.blog.constant.Constants;
import lombok.Data;

@Data
public class Result<T> {
    private int code;
    private String errMsg;
    private T data;

    public static <T> Result success(T data) {
        Result result = new Result();
        result.code = Constants.RESULT_SUCCESS;
        result.data = data;
        return result;
    }

    public static Result fail(String errMsg){
        Result result = new Result();
        result.code = Constants.RESULT_FAIL;
        result.errMsg = errMsg;
        return result;
    }

    public static <T> Result fail(String errMsg, T data){
        Result result = new Result();
        result.code = Constants.RESULT_FAIL;
        result.errMsg = errMsg;
        result.data = data;
        return result;
    }
}
